﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading;

namespace Cognitum.EmailSenders
{
    public class EmailSender : IEmailSender
    {
        public void SendAsyncEmail(string from, string to, string password, string subject, string body)
        {
            Thread email = new Thread(delegate()
              {
                  SendEmail(to, from, password, subject, body);
              });

            email.IsBackground = true;
            email.Start();
        }

        private void SendEmail(string to, string from, string password, string subject, string body)
        {
            using (MailMessage mm = new MailMessage(from, to))
            {
                mm.Subject = subject;
                mm.Body = "fds";
                mm.IsBodyHtml = false;
                SmtpClient smtp = new SmtpClient("smtp.gmail.com");
                smtp.EnableSsl = true;
                NetworkCredential NetworkCred = new NetworkCredential("cassandraprovider", password);
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = NetworkCred;
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.Send(mm);
            }
        }
    }
}